package com.zut.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zut.mapper.TeacherMapper;
import com.zut.pojo.Bookorder;
import com.zut.pojo.Parents;
import com.zut.pojo.Schdule;
import com.zut.pojo.Teacher;
import com.zut.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author teacher
 * @since 2021-05-31
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;
    @Resource
    private TeacherService teacherService;

    //按性别查询老师
    @Override
    public List<Teacher> selectTeacherSex(String sex) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teasex",sex);
        List<Teacher> teachers = teacherMapper.selectList(queryWrapper);
        return teachers;
    }

    //按教龄查询老师
    @Override
    public List<Teacher> selectTeacherYear(Integer begin, Integer end) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("teayear",begin,end);
        List<Teacher> teachers = teacherMapper.selectList(queryWrapper);
        return teachers;
    }

    //按是否获奖查询老师
    @Override
    public List<Teacher> selectTeacherIsAcmer(Integer flag) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("isacmer",flag);
        List<Teacher> teachers = teacherMapper.selectList(queryWrapper);
        return teachers;
    }

    //按名字精确查找
    @Override
    public List<Teacher> selectTeacherName(String teaName) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("realteaname",teaName);
        List<Teacher> teachers = teacherMapper.selectList(queryWrapper);
        return teachers;
    }

    //按id查找老师
    @Override
    public Teacher selectTeacherById(Integer teaid) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teaid",teaid);
        Teacher teacher = teacherMapper.selectOne(queryWrapper);
        return teacher;
    }

    //添加老师,返回1添加成功
    @Override
    public boolean addTeacher(Teacher teacher) {
        boolean i= teacherService.save(teacher);
        return i;
    }

    //删除老师，返回1删除成功
    @Override
    public int deleteTeacher(Integer teaid) {
        int i=teacherMapper.deleteById(teaid);
        return i;
    }

    //修改老师信息
    @Override
    public boolean updateTeacher(Teacher teacher) {
       boolean flag= teacherService.updateById(teacher);
        return flag;
    }

    //展示全部老师信息
    @Override
    public List<Teacher> selectAllTeacher() {
        List<Teacher> teachers = teacherService.list();
        return teachers;
    }

    //管理员模糊查询
    @Override
    public List<Teacher> seatea(String msg) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("teaid", msg)
                .or().like("teaname",msg)
                .or().like("realteaname",msg)
                .or().like("teasex",msg)
                .or().like("teayear",msg)
                .or().like("isacmer",msg)
                .or().like("teahour",msg)
                .or().like("tearesume",msg)
        ;
        List<Teacher> teacherList = teacherMapper.selectList(queryWrapper);
        return teacherList;
    }
}

